import os

import cv2
import numpy as np

add_left = 'data/rectified02/image01'
add_right = 'data/rectified02/image02'
if not os.path.exists(add_left):
    os.makedirs(add_left)
if not os.path.exists(add_right):
    os.makedirs(add_right)

left_images_path = 'D:/3D reconstruction/dataset_raw/huaxi/rectified02/image01'
right_images_path = 'D:/3D reconstruction/dataset_raw/huaxi/rectified02/image02'
left_images = sorted(os.listdir(left_images_path))
right_images = sorted(os.listdir(right_images_path))

def img_mask(images, images_path, add_path):
    for i in range(len(images)):
        image = cv2.imread(os.path.join(images_path, images[i]))
        image[image == 255] = 0
        cv2.imwrite(os.path.join(add_path, f'{i:05}.jpg'),image)

if __name__ == '__main__':
    img_mask(left_images, left_images_path, add_left)
    img_mask(right_images, right_images_path, add_right)
